<?php

class BasesfGuardRegisterActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    if ($this->getUser()->isAuthenticated())
    {
      $this->getUser()->setFlash('notice', 'You are already registered and signed in!');
      $this->redirect('@homepage');
    }

    $this->form = new sfGuardRegisterForm();
    $this->form2 = new sfGuardRegisterFormExtraField();

    if ($request->isMethod('post'))
    {
      $this->form->bind($request->getParameter($this->form->getName()));
      //$this->form2->bind($request->getParameter($this->form2->getName()));
      if ($this->form->isValid()) // && $this->form2->isValid()
      {
        $user = $this->form->save();
        $this->eeee2 = $request->getParameter($this->form2->getName());
        
        $eee2 = $request->getParameter($this->form2->getName());
        
        $data = new sfGuardUserProfile();
        $data->birth_year = $request->getParameter('birth_year');
        $data->location = $request->getParameter('location');
        $data->user_id = $user->id; 
        $data->email = $user->email_address;
        $data->sex = $request->getParameter('sex');
        $data->save();
        
        
       // $sfGuardUserProfile = $this->form2->save();

        $this->getUser()->signIn($user);

        $this->redirect('@homepage');
      }
    }
  }
}